#include "PropertyProvider.h"

PropertyProvider::PropertyProvider()
    : QObject()
{
    doubleManager = new QtDoublePropertyManager();
    doubleSpinBoxFactory = new QtDoubleSpinBoxFactory();

    intManager = new QtIntPropertyManager();
    spinBoxFactory = new QtSpinBoxFactory();

    stringManager = new QtStringPropertyManager();
    lineEditFactory = new QtLineEditFactory();

    enumManager = new QtEnumPropertyManager();
    enumFactory = new QtEnumEditorFactory();

    boolManager = new QtBoolPropertyManager();
    checkBoxFactory = new QtCheckBoxFactory();

    variantManager = new QtVariantPropertyManager();
    variantFactory = new QtVariantEditorFactory();

    fileManager = new QtFilePathPropertyManager();
    fileFactory = new QtFilePathEditorFactory();

    colorManager = new QtColorPropertyManager();
    colorFactory = new QtColorEditorFactory();

    pushButtonManager = new QtPushButtonPropertyManager();
    pushButtonFactory = new QtPushButtonFactory();

    connect(
        doubleManager, SIGNAL(valueChanged(QtProperty*, double)), this,
        SLOT(onValueChanged(QtProperty*, double))
    );
    connect(
        stringManager, SIGNAL(valueChanged(QtProperty*, QString)), this,
        SLOT(onValueChanged(QtProperty*, QString))
    );
    connect(
        intManager, SIGNAL(valueChanged(QtProperty*, int)), this,
        SLOT(onValueChanged(QtProperty*, int))
    );
    connect(
        enumManager, SIGNAL(valueChanged(QtProperty*, int)), this,
        SLOT(onValueChanged(QtProperty*, int))
    );
    connect(
        boolManager, SIGNAL(valueChanged(QtProperty*, bool)), this,
        SLOT(onValueChanged(QtProperty*, bool))
    );
    connect(
        fileManager, SIGNAL(valueChanged(QtProperty*, QString)), this,
        SLOT(onValueChanged(QtProperty*, QString))
    );
    connect(
        colorManager, SIGNAL(valueChanged(QtProperty*, QColor)), this,
        SLOT(onValueChanged(QtProperty*, QColor))
    );
    connect(
        pushButtonManager, SIGNAL(valueChanged(QtProperty*, int)), this,
        SLOT(onValueChanged(QtProperty*, int))
    );
}

void PropertyProvider::initEditor(QtTreePropertyBrowser* editor)
{
    editor_ = editor;
    editor_->setFactoryForManager(stringManager, lineEditFactory);
    editor_->setFactoryForManager(doubleManager, doubleSpinBoxFactory);
    editor_->setFactoryForManager(intManager, spinBoxFactory);
    editor_->setFactoryForManager(enumManager, enumFactory);
    editor_->setFactoryForManager(boolManager, checkBoxFactory);
    editor_->setFactoryForManager(variantManager, variantFactory);
    editor_->setFactoryForManager(fileManager, fileFactory);
    editor_->setFactoryForManager(colorManager, colorFactory);
    editor_->setFactoryForManager(pushButtonManager, pushButtonFactory);
}

void PropertyProvider::addProperty(QtProperty* property, const QString& id)
{

    propertyToId[property] = id;
    idToProperty[id] = property;
    editor_->addProperty(property);
}

void PropertyProvider::addSubProperty(
    QtProperty* parent,
    QtProperty* property,
    const QString& id
)
{
    propertyToId[property] = id;
    idToProperty[id] = property;
    parent->addSubProperty(property);
}

void PropertyProvider::valueChanged(QtProperty* property, double value) {}

void PropertyProvider::valueChanged(QtProperty* property, QString value) {}

void PropertyProvider::valueChanged(QtProperty* property, int value) {}

void PropertyProvider::valueChanged(QtProperty* property, bool value) {}

void PropertyProvider::valueChanged(QtProperty* property, const QColor& value)
{
}

void PropertyProvider::close() {}

void PropertyProvider::onValueChanged(QtProperty* property, double value)
{
    valueChanged(property, value);
}

void PropertyProvider::onValueChanged(QtProperty* property, QString value)
{
    valueChanged(property, value);
}

void PropertyProvider::onValueChanged(QtProperty* property, int value)
{
    valueChanged(property, value);
}

void PropertyProvider::onValueChanged(QtProperty* property, bool value)
{
    valueChanged(property, value);
}

void PropertyProvider::onValueChanged(QtProperty* property, const QColor& value)
{
    valueChanged(property, value);
}
